window.onload=function(){
	clickChangeStyle();
	slideChange();
	fadeChange();
}
function clickChangeStyle(){
	var bannerBottom=getByClass('bannerBottom')[0];
	var clickItem=bannerBottom.getElementsByTagName("div");
	for(var i=0;i<clickItem.length;i++){
		clickItem[i].onclick=function(){
			for (var j = 0; j < clickItem.length; j++) {
				clickItem[j].className='';
			}
			this.className="active";
		}
	}
}
function slideChange(){
	var slideList=document.getElementById('slideList');
	var left_btn=document.getElementById('left-btn');
	var right_btn=document.getElementById('right-btn');
	var timer;
	var animated=false;
	left_btn.onclick=function(){
		if(animated){
			return;
		}
		var nowLeft=parseInt(getStyle(slideList,"left"));
		if(nowLeft==0){
			nowLeft=-1992;
			slideList.style.left=nowLeft+"px";
		}
		var targetLeft=nowLeft+996;
		timer=setInterval(function(){
			animated=true;
			nowLeft+=41.5;
			if(nowLeft<=targetLeft){
				slideList.style.left=nowLeft+"px";
			}
			else{
				animated=false;
				clearInterval(timer);
			}
		},40);
	}
	right_btn.onclick=function(){
		if(animated){
			return;
		}
		var nowLeft=parseInt(getStyle(slideList,"left"));
		if(nowLeft==-2988){
			nowLeft=0;
			slideList.style.left=nowLeft+"px";
		}
		var targetLeft=nowLeft-996;
		timer=setInterval(function(){
			animated=true;
			nowLeft-=41.5;
			if(nowLeft>=targetLeft){
				slideList.style.left=nowLeft+"px";
			}
			else{
				animated=false;
				clearInterval(timer);
			}
		},40);
	}
}
function fadeChange() {
	var newsSlide=document.getElementById("newsSlide");
	var fadeItem=newsSlide.getElementsByTagName('li');
	var pointBox=document.getElementById('changePoint');
	var point=pointBox.getElementsByTagName('a');
	var fadeTimer=null;
	var animated=false;
	var index=0;
	fadeTimer=setInterval(autoFade,5000);
	for(var i=0;i<fadeItem.length;i++){
		(function(j){
			point[j].onmouseover=function(){
				clearInterval(fadeTimer);
				if(j==index){
					return;
				}
				fadeItem[index].className="";
				point[index].className="";
				fadeItem[j].className='on';
				this.className='on';
				index=j;
				opacityUp(fadeItem[j]);
			}
		})(i);
	}
	newsSlide.onmouseover=function(){
		clearInterval(fadeTimer);
	}
	newsSlide.onmouseout=function(){
		fadeTimer=setInterval(autoFade,5000);
	}
	function autoFade(){
		fadeItem[index].className='';
		point[index].className='';
		index++;
		if(index==3){
			index=0;
		}
		fadeItem[index].className='on';
		point[index].className='on';
		opacityUp(fadeItem[index]);
	}
}
function getByClass(clsName){
	var allTag=document.getElementsByTagName('*');
	var obj=[];
	for(var i=0;i<allTag.length;i++){
		if(allTag[i].className.indexOf(clsName+' ')>=0||allTag[i].className.indexOf(' '+clsName+' ')>=0||allTag[i].className.indexOf(' '+clsName)>=0){
			obj.push(allTag[i]);
		}
	}
	return obj;
}
//取样式
function getStyle(obj,attr){
	if(obj.currentStyle){//IE取样式
		return obj.currentStyle[attr];
	}else{
		return getComputedStyle(obj,false)[attr];
	}

}
function opacityUp(obj){
	obj.style.opacity=0;
	var alpha=0;
	var timer=setInterval(function(){
		alpha+=0.05;
		if(alpha<1){
			obj.style.opacity=alpha;
		}
		else{
			clearInterval(timer);
		}
		if(obj.className==""){
			clearInterval(timer);
		}
	},30);
}